home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 October
/
EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso
/
Aminet
/
dev
/
c
/
MemPools1_2.readme
< prev
next >
Wrap
Text File
|
1995-07-02
|
7KB
|
194 lines
Short: Malloc() replacement using Exec pools
Author: jochen.wiedmann@uni-tuebingen.de
Uploader: jochen.wiedmann@uni-tuebingen.de
Type: dev/c
MemPools - malloc() replacement using standard Exec memory pools
================================================================
Many people don't like using malloc() and similar functions because
they think it's too slow and gives too much overhead. Well, as far as
I can say they're alright, at least for users of Dice and SAS/C:
The Exec pool functions seem to be at least 5 times faster and it
can even be faster than the malloc() of GNU C! (See "Timings" below.)
Other people like malloc(): It's portable and rather easy to use.
I am one of these, however I don't want to loose the speed of
pool functions.
The mempools package is a link library with the functions malloc(),
calloc(), realloc(), strdup() and free(). It replaces the compilers
own functions by just linking against this library. No additional
work is required as the library takes use of the compilers auto-
initialization facility.
Ths autoinitialization restricts use of the mempools library to
users of Dice, SAS/C and gcc: I don't know how to handle other
compilers.
Note, that pools are available not only for users of OS 3.x! The
current amiga.lib offers replacements which call exec.library,
if the OS is 3.x and emulate pools otherwise. The MemPools
library uses this replacements.
A debugging possibility very similar to Mungwall is integrated into
the library, which is enabled by compiling with -DDEBUG. The makefiles
provide a target "mempoolsd.lib" which does just that.
1.) Disclaimer: Copyrights, (No) Warranty
-----------------------------------------
This program is Copyright (C) 1994 Jochen Wiedmann
Am Eisteich 9
72555 Metzingen
Germany
Phone: (0049) +7123 / 14881
Mail: jochen.wiedmann@uni-tuebingen.de
Permission is granted to make and distribute either verbatim and modified
copies of this documentation and the library MemPools provided the copyright
notice and this permission notice are preserved on all copies and the "GNU
General Public License" (in the file COPYING) is distributed as well.
The author gives ABSOLUTELY NO warranty that the software described in this
documentation and the results produced by them are correct. The author
cannot be held responsible for ANY damage resulting from the use of this
software.
2.) Installation
----------------
There are four libraries included in the distribution, it depends
on your compiler which one you need: mempoolss.lib and mempoolssr.lib
are for dice, they should be copied to DLIB: or a similar place.
mempools.lib is for SAS/C, its destination is sc:lib. Finally
libmempools.a is the GNU-c version which should go to GNU:lib.
If you want to recreate them, just type smake (SAS/C) or make (GNU-c).
Dice, however, requires different libraries, depending on the data
model, the type of argument handling and so on.
To create a certain library just type
lbmake mempools s (for mempoolss.lib)
lbmake mempools s r (for mempoolssr.lib)
lbmake mempools l (for mempoolsl.lib)
lbmake mempools d s (for mempoolsds.lib)
.
.
.
3.) Usage
---------
All you have to do is to link against the mempools or mempoolsd library.
a) Dice
Add the option -lmempools to your compiler statement. By adding
it to the environment variable "DCCOPTS" you get this automatically.
b) SAS/C
Add the option LIB mempools to your compiler statement. By using
the "scopts" program you can get this automatically, too.
c) gcc
Add the option -lmempools to your compiler statement. I don't know
if gcc can handle this automatically. Probably someone can
enlighten me?
However, you might be interested in controlling the pools attributes.
This can be done by creating global variables __MemPoolPuddleSize,
__MemPoolThreshSize and __MemPoolFlags which correspond to the
arguments of the CreatePool() function. For example, if you want
to modify the puddle size (this can increase speed, see "Timings"
below), just add the following line somewhere to your program:
ULONG __MemPoolPuddleSize = 16384; /* Default: 4096 */
Or if you want malloc() to obtain chip memory, just write
#include <exec/memory.h>
ULONG __MemPoolFlags = MEMF_CHIP; /* Default: MEMF_ANY */
If you don't have amiga.lib, version 39 or later, you will miss
functions like LibAllocPooled(), LibCreatePool() and so on. In that
case you might wish to compile the file pools.c and add it to the
library. It contains functions, that call the respective Exec
functions in OS 39 or later and emulate them otherwise. However,
please note, that I did *NEVER* do some serious checks on them. I have
just retyped them from a german magazine.
4.) Timings
-----------
I wrote a little timing program. (I don't claim that it is very good,
probably someone can write a better one.) I was rather surprised about
the results:
Compiler Time (Mins:Secs) Notes
Dice 2:46,74 Dice maps malloc() to AllocMem()
directly. This is extremely poor!
Especially the exit() function
needs about 20% of the programs
time.
SAS/C 1:17,66 SAS/C uses an own pool system.
Thus the exit() function is
rather fast. malloc(), however,
seems to be slow.
gcc 0:12,84 (ixemul) gcc uses a pool system which is
0:14,34 (libnix) rather close to Exec pools. This
gives good results.
MemPools 0:15,10 (4096) By increasing the puddle size
0:12,14 (8192) (see "Usage") you get better
0:10,80 (16384) results! It seems worth to try a
little bit.
============================= Archive contents =============================
Original Packed Ratio Date Time Name
-------- ------- ----- --------- -------- -------------
1547 806 47.8% 22-May-95 08:51:16 +calloc.c
17982 6993 61.1% 26-Mar-95 20:18:20 +COPYING
3534 1322 62.5% 22-May-95 08:53:12 +DMakefile
2285 1100 51.8% 22-May-95 08:51:26 +free.c
3499 1513 56.7% 22-May-95 08:51:36 +init.c
1570 596 62.0% 02-May-95 15:33:04 +lib.def
2742 892 67.4% 10-May-95 16:41:06 +libmempools.a
3456 1278 63.0% 22-May-95 08:50:34 +Makefile
2101 1032 50.8% 22-May-95 08:51:04 +malloc.c
59 59 0.0% 26-Mar-95 20:18:22 +MemPoolFlags.c
60 60 0.0% 26-Mar-95 20:18:22 +MemPoolPuddleSize.c
2055 992 51.7% 10-May-95 16:43:44 +mempools.h
1468 666 54.6% 22-May-95 08:57:54 +mempools.lib
5637 2482 55.9% 22-May-95 08:55:02 +MemPools.readme
2044 738 63.8% 22-May-95 08:55:58 +mempoolss.lib
1984 719 63.7% 22-May-95 08:56:48 +mempoolssr.lib
59 59 0.0% 26-Mar-95 20:18:22 +MemPoolThreshSize.c
5031 1612 67.9% 10-May-95 14:02:54 +Pools.c
1756 883 49.7% 22-May-95 08:52:30 +realloc.c
2948 1176 60.1% 22-May-95 08:50:44 +SMakefile
1522 796 47.7% 22-May-95 08:52:42 +strdup.c
5029 1826 63.6% 02-May-95 13:51:04 +TimeMem.c
2861 1308 54.2% 26-Mar-95 20:18:20 +TimeProg.c
-------- ------- ----- --------- --------
71229 28908 59.4% 13-Jun-95 08:22:16 23 files